using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using Catastrophe.Common.AttributeEx;
using Catastrophe.Common.SoftLicensing;

namespace Catastrophe.AutoSulution.EDC
{
	public class EnDeCode
	{
		/// <summary>
		///     将T类型的小端数据转换为大端
		/// </summary>
		/// <param name="value"></param>
		/// <param name="endianMode"></param>
		/// <param name="reverseByte">强制高低字节转换null的时候正常进行大小端判断，否则根据设定值强制转换或者忽略</param>
		public static void GenericLeToBe<T>(ref T value, EndianModeEnum endianMode = EndianModeEnum.Big, ForceChangeHlByteEnum? reverseByte = null)
		{
			dynamic val = value;
			byte[] byteAry = BitConverter.GetBytes(val);
			value = EnDeCode.ConvertByteBufToT<T>(byteAry, 0, endianMode, reverseByte);
		}

		/// <summary>
		///     转字节数组(有装箱拆箱)
		/// </summary>
		/// <param name="value"></param>
		/// <param name="endianMode"></param>
		/// <param name="reverseByte">强制高低字节转换null的时候正常进行大小端判断，否则根据设定值强制转换或者忽略</param>
		/// <param name="strEncode">只有涉及string类型的时候使用,字符串编码常用:ASCII、UTF-8、GB2312、GBK</param>
		/// <returns></returns>
		public static byte[] ConvertToByteBuf(dynamic value, EndianModeEnum endianMode = EndianModeEnum.Big, ForceChangeHlByteEnum? reverseByte = null, string strEncode = "ASCII")
		{
			Type type = value.GetType();
			if (type == typeof(byte))
			{
				return new byte[1] { value };
			}
			byte[] array = ((!(value is string)) ? ((byte[])BitConverter.GetBytes(value)) : ((byte[])(string.IsNullOrWhiteSpace(strEncode) ? Encoding.ASCII.GetBytes(value) : Encoding.GetEncoding(strEncode).GetBytes(value))));
			if (array == null)
			{
				return null;
			}
			if (!reverseByte.HasValue || reverseByte == ForceChangeHlByteEnum.Normal)
			{
				if (BitConverter.IsLittleEndian != (endianMode == EndianModeEnum.Little))
				{
					Array.Reverse(array);
				}
			}
			else if (reverseByte == ForceChangeHlByteEnum.Reverse)
			{
				Array.Reverse(array);
			}
			return array;
		}

		/// <summary>
		///     将value转字节数组，并在现有数组后面添加
		/// </summary>
		/// <param name="data">数组</param>
		/// <param name="value">数值</param>
		public static void ConvertToByteBuf(ref byte[] data, dynamic value)
		{
			Type type = value.GetType();
			if (type == typeof(byte))
			{
				data = new byte[1] { value };
			}
			List<byte> list = new List<byte>(data);
			byte[] array = BitConverter.GetBytes(value);
			if (array != null)
			{
				if (BitConverter.IsLittleEndian)
				{
					Array.Reverse(array);
				}
				list.AddRange(array);
				data = list.ToArray();
			}
		}

		/// <summary>
		///     字节数组转指定类型
		/// </summary>
		/// <param name="byteAry">目标数组</param>
		/// <param name="arrayStart">解析起始位</param>
		/// <param name="endianMode">大小端</param>
		/// <param name="reverseByte"></param>
		/// <returns></returns>
		public static T ConvertByteBufToT<T>(IEnumerable<byte> byteAry, int arrayStart = 0, EndianModeEnum endianMode = EndianModeEnum.Big, ForceChangeHlByteEnum? reverseByte = null)
		{
			Type typeFromHandle = typeof(T);
			return EnDeCode.ConvertByteBufToT(typeFromHandle, byteAry, arrayStart, endianMode, reverseByte);
		}

		/// <summary>
		/// 类型变更
		/// </summary>
		/// <typeparam name="T">目标类型</typeparam>
		/// <param name="vlaue">当前数值</param>
		/// <param name="mode">大小端</param>
		/// <returns></returns>
		public static T ConvertToDstType<T>(dynamic vlaue, EndianModeEnum mode = EndianModeEnum.Little)
		{
			Type typeFromHandle = typeof(T);
			dynamic bytes = BitConverter.GetBytes(vlaue);
			dynamic val = EnDeCode.ConvertByteBufToT(typeFromHandle, bytes, 0, mode);
			return val;
		}

		/// <summary>
		/// 类型变更
		/// </summary>
		/// <param name="vlaue">当前数值</param>
		/// <param name="type">目标类型</param>
		/// <param name="mode">大小端</param>
		public static void ConvertToDstType(ref dynamic vlaue, Type type, EndianModeEnum mode = EndianModeEnum.Little)
		{
			dynamic bytes = BitConverter.GetBytes(vlaue);
			vlaue = EnDeCode.ConvertByteBufToT(type, bytes, 0, mode);
		}

		/// <summary>
		///     字节数组解析指定类型
		/// </summary>
		/// <param name="descT">类型</param>
		/// <param name="byteAry">字节数组</param>
		/// <param name="arrayStart">起始</param>
		/// <param name="endianMode">编码类型</param>
		/// <param name="reverseByte">高低字节</param>
		/// <returns></returns>
		public static dynamic ConvertByteBufToT(Type descT, IEnumerable<byte> byteAry, int arrayStart = 0, EndianModeEnum endianMode = EndianModeEnum.Big, ForceChangeHlByteEnum? reverseByte = null)
		{
			if (descT == null)
			{
				throw new ArgumentNullException("descT");
			}
			byte[] array = null;
			object result;
			if (descT.IsValueType)
			{
				result = 0;
				int num = Marshal.SizeOf(descT);
				array = new byte[num];
				if (byteAry.Count() - arrayStart < num)
				{
					return result;
				}
				Array.Copy(byteAry.ToArray(), arrayStart, array, 0, num);
				if (!reverseByte.HasValue || reverseByte == ForceChangeHlByteEnum.Normal)
				{
					if (BitConverter.IsLittleEndian != (endianMode == EndianModeEnum.Little))
					{
						Array.Reverse(array);
					}
				}
				else if (reverseByte == ForceChangeHlByteEnum.Reverse)
				{
					Array.Reverse(array);
				}
			}
			else
			{
				result = "";
				int num = byteAry.Count() - arrayStart;
				array = new byte[num];
				Array.Copy(byteAry.ToArray(), arrayStart, array, 0, num);
			}
			switch (descT.Name)
			{
			case "Byte":
				result = array[0];
				break;
			case "Int16":
				result = BitConverter.ToInt16(array, 0);
				break;
			case "UInt16":
				result = BitConverter.ToUInt16(array, 0);
				break;
			case "Int32":
				result = BitConverter.ToInt32(array, 0);
				break;
			case "UInt32":
				result = BitConverter.ToUInt32(array, 0);
				break;
			case "Int64":
				result = BitConverter.ToInt64(array, 0);
				break;
			case "UInt64":
				result = BitConverter.ToUInt64(array, 0);
				break;
			case "Single":
				result = BitConverter.ToSingle(array, 0);
				break;
			case "Double":
				result = BitConverter.ToDouble(array, 0);
				break;
			case "String":
				result = Encoding.ASCII.GetString(array).Trim();
				break;
			}
			return result;
		}

		/// <summary>
		/// 获取类型的默认值
		/// </summary>
		/// <param name="typeName">类型</param>
		/// <returns></returns>
		public static object GetDefaultTypeValue(string typeName)
		{
			Type type = EnDeCode.GetType(typeName);
			if (type != null)
			{
				return type.IsValueType ? Activator.CreateInstance(type) : null;
			}
			return null;
		}

		/// <summary>
		/// 通过名称获取类型
		/// </summary>
		/// <param name="typeName">类型</param>
		/// <returns></returns>
		public static Type GetType(string typeName)
		{
			switch (typeName.ToLower())
			{
			case "bool":
			case "boolean":
			case "system.boolean":
				return typeof(bool);
			case "byte":
			case "system.byte":
				return typeof(byte);
			case "sbyte":
			case "system.sbyte":
				return typeof(sbyte);
			case "char":
			case "system.char":
				return typeof(char);
			case "int16":
			case "short":
			case "system.int16":
				return typeof(short);
			case "uint16":
			case "ushort":
			case "system.uint16":
				return typeof(ushort);
			case "int32":
			case "int":
			case "system.int32":
				return typeof(int);
			case "uint32":
			case "uint":
			case "system.uint32":
				return typeof(uint);
			case "int64":
			case "long":
			case "system.int64":
				return typeof(long);
			case "uint64":
			case "ulong":
			case "system.uint64":
				return typeof(ulong);
			case "single":
			case "float":
			case "system.single":
				return typeof(float);
			case "double":
			case "system.double":
				return typeof(double);
			case "system.decimal":
			case "decimal":
				return typeof(decimal);
			case "string":
			case "system.string":
				return typeof(string);
			case "system.object":
			case "object":
				return typeof(object);
			case "system.datetime":
			case "datetime":
				return typeof(DateTime);
			case "system.guid":
			case "guid":
				return typeof(Guid);
			default:
				return null;
			}
		}

		/// <summary>
		///     //index从0开始
		/// </summary>
		/// <param name="b">字节</param>
		/// <param name="index">位</param>
		/// <returns></returns>
		public static bool ReturnGetbitValue(byte b, int index)
		{
			return (((b & (1 << index)) > 0) ? 1 : 0) == 1;
		}

		/// <summary>
		///     将第index位设为1
		/// </summary>
		/// <param name="b">字节</param>
		/// <param name="index">位</param>
		/// <returns></returns>
		public static byte ReturnSetBit(byte b, int index)
		{
			return (byte)(b | (1 << index));
		}

		/// <summary>
		/// 将第index位设为1
		/// </summary>
		/// <param name="b">字节</param>
		/// <param name="index">位</param>
		public static void SetBit(ref byte b, int index)
		{
			b = (byte)(b | (1 << index));
		}

		/// <summary>
		///     将第index位设为0
		/// </summary>
		/// <param name="b">字节</param>
		/// <param name="index">位</param>
		/// <returns></returns>
		public static byte ReturnClearBit(byte b, int index)
		{
			return (byte)(b & (255 - (1 << index)));
		}

		/// <summary>
		/// 将第index位设为0
		/// </summary>
		/// <param name="b">字节</param>
		/// <param name="index">位</param>
		public static void ClearBit(ref byte b, int index)
		{
			b = (byte)(b & (255 - (1 << index)));
		}

		/// <summary>
		///     将bool数组转换到byte数组 -&gt;
		///     Converting a bool array to a byte array
		/// </summary>
		/// <param name="array">bool数组</param>
		/// <returns>转换后的字节数组</returns>
		/// <example>
		///     <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\BasicFramework\SoftBasicExample.cs" region="BoolArrayToByte" title="BoolArrayToByte示例" />
		/// </example>
		public static byte[] BoolArrayToByte(bool[] array)
		{
			if (array == null)
			{
				return null;
			}
			int num = ((array.Length % 8 == 0) ? (array.Length / 8) : (array.Length / 8 + 1));
			byte[] array2 = new byte[num];
			for (int i = 0; i < array.Length; i++)
			{
				int num2 = i / 8;
				int num3 = i % 8;
				byte b = 0;
				switch (num3)
				{
				case 0:
					b = 1;
					break;
				case 1:
					b = 2;
					break;
				case 2:
					b = 4;
					break;
				case 3:
					b = 8;
					break;
				case 4:
					b = 16;
					break;
				case 5:
					b = 32;
					break;
				case 6:
					b = 64;
					break;
				case 7:
					b = 128;
					break;
				}
				if (array[i])
				{
					array2[num2] += b;
				}
			}
			return array2;
		}

		/// <summary>
		///     从Byte数组中提取位数组，length代表位数 -&gt;
		///     Extracts a bit array from a byte array, length represents the number of digits
		/// </summary>
		/// <param name="inBytes">原先的字节数组</param>
		/// <param name="length">想要转换的长度，如果超出自动会缩小到数组最大长度</param>
		/// <returns>转换后的bool数组</returns>
		/// <example>
		///     <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\BasicFramework\SoftBasicExample.cs" region="ByteToBoolArray" title="ByteToBoolArray示例" />
		/// </example>
		public static bool[] ByteToBoolArray(byte[] inBytes, int length)
		{
			if (inBytes == null)
			{
				return null;
			}
			if (length > inBytes.Length * 8)
			{
				length = inBytes.Length * 8;
			}
			bool[] array = new bool[length];
			for (int i = 0; i < length; i++)
			{
				int num = i / 8;
				int num2 = i % 8;
				byte b = 0;
				switch (num2)
				{
				case 0:
					b = 1;
					break;
				case 1:
					b = 2;
					break;
				case 2:
					b = 4;
					break;
				case 3:
					b = 8;
					break;
				case 4:
					b = 16;
					break;
				case 5:
					b = 32;
					break;
				case 6:
					b = 64;
					break;
				case 7:
					b = 128;
					break;
				}
				if ((inBytes[num] & b) == b)
				{
					array[i] = true;
				}
			}
			return array;
		}

		/// <summary>
		///     将第index位取反
		/// </summary>
		/// <param name="b">字节</param>
		/// <param name="index">位</param>
		/// <returns></returns>
		public static byte ReturnReverseBit(byte b, int index)
		{
			return (byte)(b ^ (byte)(1 << index));
		}

		/// <summary>
		/// 将第index位取反
		/// </summary>
		/// <param name="b">字节</param>
		/// <param name="index">位</param>
		public static void ReverseBit(ref byte b, int index)
		{
			b ^= (byte)(1 << index);
		}

		/// <summary>
		///     字节数组转16进制字符串(01-"01")
		/// </summary>
		/// <param name="bytes">字节数组</param>
		/// <param name="len">长度</param>
		/// <returns></returns>
		public static string ByteToHexStr(byte[] bytes, int len)
		{
			return EnDeCode.ByteToHexStr(bytes, 0, len);
		}

		/// <summary>
		///  字节数组转16进制字符串(01-"01")
		/// </summary>
		/// <param name="bytes">字节数组</param>
		/// <param name="startIndex">起始</param>
		/// <param name="len">长度</param>
		/// <returns></returns>
		public static string ByteToHexStr(byte[] bytes, int startIndex, int len)
		{
			string text = "";
			int num = startIndex + len;
			for (int i = startIndex; i < num; i++)
			{
				string text2 = text;
				DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(1, 1);
				defaultInterpolatedStringHandler.AppendFormatted(bytes[i], "X2");
				defaultInterpolatedStringHandler.AppendLiteral(" ");
				text = text2 + defaultInterpolatedStringHandler.ToStringAndClear();
			}
			return text;
		}

		/// <summary>
		/// BCD（0-9）转int 0x11,0x12-&gt;1112
		/// </summary>
		/// <param name="bytes">字节数组</param>
		/// <param name="startIndex">起始</param>
		/// <param name="len">长度</param>
		/// <returns></returns>
		public static int? BCDToInt(byte[] bytes, int startIndex, int len)
		{
			string text = "";
			int num = startIndex + len;
			for (int i = startIndex; i < num; i++)
			{
				string text2 = text;
				DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(0, 1);
				defaultInterpolatedStringHandler.AppendFormatted(bytes[i], "X2");
				text = text2 + defaultInterpolatedStringHandler.ToStringAndClear();
			}
			if (!Regex.IsMatch(text, "^[0-9]*$"))
			{
				return null;
			}
			return int.Parse(text);
		}

		/// <summary>
		/// 101-&gt;00 00 01 01
		/// </summary>
		/// <param name="value"></param>
		/// <param name="length"></param>
		/// <returns></returns>
		public static byte[] IntToBCD(int value, int length = 4)
		{
			DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(1, 1);
			defaultInterpolatedStringHandler.AppendLiteral("D");
			defaultInterpolatedStringHandler.AppendFormatted(length * 2);
			string hexString = value.ToString(defaultInterpolatedStringHandler.ToStringAndClear());
			return EnDeCode.StrToToHexByte(hexString);
		}

		/// <summary>
		/// BCD转Single
		/// </summary>
		/// <param name="bytes">字节数组</param>
		/// <param name="startIndex">起始</param>
		/// <param name="len">长度</param>
		/// <returns></returns>
		public static double? BCDToSingle(byte[] bytes, int startIndex, int len)
		{
			string text = "";
			int num = startIndex + len;
			for (int i = startIndex; i < num; i++)
			{
				string text2 = text;
				DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(0, 1);
				defaultInterpolatedStringHandler.AppendFormatted(bytes[i], "X2");
				text = text2 + defaultInterpolatedStringHandler.ToStringAndClear();
			}
			if (!Regex.IsMatch(text, "^[0-9E]*$"))
			{
				return null;
			}
			text = text.Replace("E", ".");
			return double.Parse(text);
		}

		/// <summary>
		/// Single-&gt;BCD
		/// </summary>
		/// <param name="value">double</param>
		/// <param name="length">长度</param>
		/// <returns></returns>
		public static byte[] SingleToBCD(double value, int length = 4)
		{
			string text = value.ToString().Replace('.', 'E');
			int num = length * 2 - text.Length;
			if (num <= 0)
			{
				return null;
			}
			string text2 = new string('0', num);
			text2 += text;
			return EnDeCode.StrToToHexByte(text2.ToString());
		}

		/// <summary>
		///     字符串转16进制数组("0102"-01 02)
		/// </summary>
		/// <param name="hexString">十六进制字符串</param>
		/// <returns></returns>
		public static byte[] StrToToHexByte(string hexString)
		{
			hexString = hexString.Replace(" ", "");
			if (hexString.Length % 2 != 0)
			{
				hexString += " ";
			}
			byte[] array = new byte[hexString.Length / 2];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
			}
			return array;
		}

		/// <summary>
		///     字符串单个字符转byte("01 02"-30 31 30 32)
		/// </summary>
		/// <param name="str">字符串</param>
		/// <returns></returns>
		public static byte[] AsciiToByte(string str)
		{
			List<byte> list = new List<byte>();
			if (string.IsNullOrEmpty(str))
			{
				return list.ToArray();
			}
			str = str.Replace(" ", "");
			char[] array = str.ToArray();
			char[] array2 = array;
			foreach (char value in array2)
			{
				list.Add(Convert.ToByte(value));
			}
			return list.ToArray();
		}

		/// <summary>
		///     字节数组编码转ASCII再转Byte数组（01-('0'+'1')-30 31）
		/// </summary>
		/// <param name="buf">字节数组</param>
		/// <param name="startIndex">起始</param>
		/// <param name="length">长度</param>
		/// <returns></returns>
		public static byte[] AsciiToByte(byte[] buf, int startIndex, int length)
		{
			byte[] array = new byte[length];
			Array.Copy(buf, startIndex, array, 0, length);
			string text = "";
			byte[] array2 = array;
			foreach (byte value in array2)
			{
				string text2 = text;
				DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(1, 1);
				defaultInterpolatedStringHandler.AppendFormatted(value, "X2");
				defaultInterpolatedStringHandler.AppendLiteral(" ");
				text = text2 + defaultInterpolatedStringHandler.ToStringAndClear();
			}
			text = text.Replace(" ", "");
			return Encoding.Default.GetBytes(text);
		}

		/// <summary>
		/// 60-&gt;0060-&gt;30 30 36 30
		/// </summary>
		/// <param name="value">数值</param>
		/// <param name="length">长度</param>
		/// <returns></returns>
		public static byte[] AsciiToByte(int value, int length = 4)
		{
			return EnDeCode.AsciiToByte(value.ToString(new string('0', length)));
		}

		/// <summary>
		///     字节数组解码（(30 31)-('0'+'1')-01）
		/// </summary>
		/// <param name="buf">字节数组</param>
		/// <param name="startIndex">起始</param>
		/// <param name="length">长度</param>
		/// <returns></returns>
		public static byte[] ByteToAscii(byte[] buf, int startIndex, int length)
		{
			List<byte> list = new List<byte>();
			byte[] array = new byte[length];
			Array.Copy(buf, startIndex, array, 0, length);
			char[] chars = Encoding.ASCII.GetChars(array);
			int num = ((chars.Length % 2 == 0) ? chars.Length : (chars.Length - 1));
			for (int i = 0; i < num; i += 2)
			{
				string value = new string(new char[2]
				{
					chars[i],
					chars[i + 1]
				});
				byte item = Convert.ToByte(value, 16);
				list.Add(item);
			}
			return list.ToArray();
		}

		/// <summary>
		///     字节数组转字符串
		/// </summary>
		/// <param name="buf">数组</param>
		/// <param name="startIndex">起始</param>
		/// <param name="length">长度</param>
		/// <returns></returns>
		public static string ByteToAsciiStr(byte[] buf, int startIndex, int length)
		{
			byte[] array = new byte[length];
			Array.Copy(buf, startIndex, array, 0, length);
			char[] chars = Encoding.ASCII.GetChars(array);
			return new string(chars);
		}

		/// <summary>
		///     字符串分割并转换格式
		/// </summary>
		/// <typeparam name="T1">类1</typeparam>
		/// <typeparam name="T2">类2</typeparam>
		/// <param name="str">字符串</param>
		/// <param name="splitFlag">分割字符</param>
		/// <returns></returns>
		public static Tuple<bool, T1, T2> GetStrSplit<T1, T2>(string str, char splitFlag)
		{
			try
			{
				if (!str.Contains(splitFlag))
				{
					return new Tuple<bool, T1, T2>(item1: false, default(T1), default(T2));
				}
				string[] array = str.Trim().Split(splitFlag);
				if (array.Length < 2)
				{
					return new Tuple<bool, T1, T2>(item1: false, default(T1), default(T2));
				}
				T1 item = (T1)Convert.ChangeType(array[0], typeof(T1));
				T2 item2 = (T2)Convert.ChangeType(array[1], typeof(T2));
				return new Tuple<bool, T1, T2>(item1: true, item, item2);
			}
			catch
			{
				return new Tuple<bool, T1, T2>(item1: false, default(T1), default(T2));
			}
		}

		/// <summary>
		///     字符串分割并转换格式
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="str">字符串</param>
		/// <param name="splitFlag">分割字符</param>
		/// <param name="notInluceFlagFailed">true:如果不包含分隔符返回失败 false:不包含分隔符返回str</param>
		/// <returns></returns>
		public static Tuple<bool, List<T>> GetStrSplit<T>(string str, string splitFlag, bool notInluceFlagFailed = true)
		{
			try
			{
				if (string.IsNullOrWhiteSpace(str))
				{
					return new Tuple<bool, List<T>>(item1: false, new List<T>());
				}
				if (!str.Contains(splitFlag))
				{
					return notInluceFlagFailed ? new Tuple<bool, List<T>>(item1: false, new List<T>()) : new Tuple<bool, List<T>>(item1: true, new List<T> { (T)Convert.ChangeType(str.Trim(), typeof(T)) });
				}
				string[] array = str.Trim().Split(splitFlag.ToCharArray());
				List<T> list = new List<T>();
				string[] array2 = array;
				foreach (string text in array2)
				{
					if (!text.Trim().Equals(string.Empty))
					{
						list.Add((T)Convert.ChangeType(text.Trim(), typeof(T)));
					}
				}
				return new Tuple<bool, List<T>>(item1: true, list);
			}
			catch
			{
				return new Tuple<bool, List<T>>(item1: false, new List<T>());
			}
		}

		/// <summary>
		///     首字母大写其他小写
		/// </summary>
		/// <param name="value">字符串</param>
		/// <returns></returns>
		public string StrFirstToUpper(string value)
		{
			if (string.IsNullOrWhiteSpace(value))
			{
				return string.Empty;
			}
			return value.Substring(0, 1).ToUpper() + value.Substring(1).ToLower();
		}

		/// <summary>
		///     字符串指定位置、长度转换大写，其他均小写
		/// </summary>
		/// <param name="value">字符串</param>
		/// <param name="startIndex">起始</param>
		/// <param name="count">数量</param>
		/// <returns></returns>
		public static string StrToUpper(string value, int startIndex = 0, int count = 1)
		{
			if (string.IsNullOrWhiteSpace(value))
			{
				return string.Empty;
			}
			if (startIndex > value.Length - 1)
			{
				DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(11, 2);
				defaultInterpolatedStringHandler.AppendLiteral("起始字符位置");
				defaultInterpolatedStringHandler.AppendFormatted(startIndex);
				defaultInterpolatedStringHandler.AppendLiteral(">最大索引");
				defaultInterpolatedStringHandler.AppendFormatted(value.Length - 1);
				throw new Exception(defaultInterpolatedStringHandler.ToStringAndClear());
			}
			if (count > value.Length - startIndex)
			{
				DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(9, 2);
				defaultInterpolatedStringHandler.AppendLiteral("目标长度");
				defaultInterpolatedStringHandler.AppendFormatted(count);
				defaultInterpolatedStringHandler.AppendLiteral(">允许长度");
				defaultInterpolatedStringHandler.AppendFormatted(value.Length - startIndex);
				throw new Exception(defaultInterpolatedStringHandler.ToStringAndClear());
			}
			string text = value.Substring(0, startIndex).ToLower();
			string text2 = value.Substring(startIndex, count).ToUpper();
			string text3 = value.Substring(startIndex + count, value.Length - startIndex - count).ToLower();
			return text + text2 + text3;
		}

		/// <summary>
		///     字符串指定位置、长度转换小写，其他均大写
		/// </summary>
		/// <param name="value">字符串</param>
		/// <param name="startIndex">起始</param>
		/// <param name="count">数量</param>
		/// <returns></returns>
		public static string StrToLower(string value, int startIndex = 0, int count = 1)
		{
			if (string.IsNullOrWhiteSpace(value))
			{
				return string.Empty;
			}
			if (startIndex > value.Length - 1)
			{
				DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(11, 2);
				defaultInterpolatedStringHandler.AppendLiteral("起始字符位置");
				defaultInterpolatedStringHandler.AppendFormatted(startIndex);
				defaultInterpolatedStringHandler.AppendLiteral(">最大索引");
				defaultInterpolatedStringHandler.AppendFormatted(value.Length - 1);
				throw new Exception(defaultInterpolatedStringHandler.ToStringAndClear());
			}
			if (count > value.Length - startIndex)
			{
				DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(9, 2);
				defaultInterpolatedStringHandler.AppendLiteral("目标长度");
				defaultInterpolatedStringHandler.AppendFormatted(count);
				defaultInterpolatedStringHandler.AppendLiteral(">允许长度");
				defaultInterpolatedStringHandler.AppendFormatted(value.Length - startIndex);
				throw new Exception(defaultInterpolatedStringHandler.ToStringAndClear());
			}
			string text = value.Substring(0, startIndex).ToUpper();
			string text2 = value.Substring(startIndex, count).ToLower();
			string text3 = value.Substring(startIndex + count, value.Length - startIndex - count).ToUpper();
			return text + text2 + text3;
		}

		/// <summary>
		///     sql连接字符串
		/// </summary>
		/// <param name="ip">IP</param>
		/// <param name="dbName">数据库名</param>
		/// <param name="userName">用户名</param>
		/// <param name="pwd">密码</param>
		/// <param name="timeout">超时</param>
		/// <returns></returns>
		public static string SqlDbFormat(string ip, string dbName, string userName, string pwd, int timeout = 1000)
		{
			DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(54, 5);
			defaultInterpolatedStringHandler.AppendLiteral("Server =");
			defaultInterpolatedStringHandler.AppendFormatted(ip);
			defaultInterpolatedStringHandler.AppendLiteral("; Database =");
			defaultInterpolatedStringHandler.AppendFormatted(dbName);
			defaultInterpolatedStringHandler.AppendLiteral("; uid =");
			defaultInterpolatedStringHandler.AppendFormatted(userName);
			defaultInterpolatedStringHandler.AppendLiteral("; pwd =");
			defaultInterpolatedStringHandler.AppendFormatted(pwd);
			defaultInterpolatedStringHandler.AppendLiteral("; Connect Timeout = ");
			defaultInterpolatedStringHandler.AppendFormatted(timeout);
			return defaultInterpolatedStringHandler.ToStringAndClear();
		}

		/// <summary>
		///     sqlite连接字符串
		/// </summary>
		/// <param name="dbPath">路径</param>
		/// <param name="dbName">数据库名</param>
		/// <param name="pwd">密码</param>
		/// <param name="version">版本</param>
		/// <returns></returns>
		public static string SqliteDbFormat(string dbName, string pwd = "", string dbPath = "", string version = "3")
		{
			if (string.IsNullOrEmpty(dbPath))
			{
				dbPath = AppDomain.CurrentDomain.BaseDirectory;
			}
			if (!string.IsNullOrEmpty(pwd))
			{
				pwd = "Password = " + pwd + ";";
			}
			DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(27, 3);
			defaultInterpolatedStringHandler.AppendLiteral("Data Source = ");
			defaultInterpolatedStringHandler.AppendFormatted(Path.Combine(dbPath, dbName));
			defaultInterpolatedStringHandler.AppendLiteral(".db;Version=");
			defaultInterpolatedStringHandler.AppendFormatted(version);
			defaultInterpolatedStringHandler.AppendLiteral(";");
			defaultInterpolatedStringHandler.AppendFormatted(pwd);
			return defaultInterpolatedStringHandler.ToStringAndClear();
		}

		/// <summary>
		/// 转float
		/// </summary>
		/// <param name="value"></param>
		/// <param name="digital"></param>
		/// <returns></returns>
		public static float ConvertToSingle(dynamic value, int digital = 3)
		{
			return Convert.ToSingle(Math.Round(value, digital));
		}

		/// <summary>
		/// 默认加密绑定信息
		/// </summary>
		/// <returns></returns>
		public static string CreateDefaultLicensePwd(string serialNo = "")
		{
			if (string.IsNullOrWhiteSpace(serialNo))
			{
				serialNo = ComputerInfo.GetBIOSInfo();
			}
			List<byte> list = EnDeCode.AsciiToByte(serialNo).ToList();
			byte item = CheckOuts.CheckCc(list.ToArray());
			list.Add(item);
			return EnDeCode.ByteToHexStr(list.ToArray(), list.Count);
		}

		/// <summary>
		/// 十六进制转十进制 10-&gt;0X10即16
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		public static int HexToDecima(string value)
		{
			return int.Parse(value, NumberStyles.HexNumber);
		}
	}
}
